<!--
  * 任务列表
-->
<template>
  <a-form class="smart-query-form">
    <a-row class="smart-query-form-row">
      <a-form-item label="客户名称" class="smart-query-form-item" name="name">
        <a-input style="width: 600px" v-model:value="queryForm.name" placeholder="请输入客户名称" />
      </a-form-item>
      <a-form-item class="smart-query-form-item smart-margin-left10">
        <a-button type="primary" @click="ajaxQuery">
          <template #icon>
            <SearchOutlined />
          </template>
          查询
        </a-button>
        <a-button @click="resetQuery">
          <template #icon>
            <ReloadOutlined />
          </template>
          重置
        </a-button>
      </a-form-item>
    </a-row>
  </a-form>

  <a-card size="small" :bordered="false" :hoverable="true">
    <a-table :scroll="{ x: 1000 }" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      size="small" :dataSource="tableData" :columns="columns" rowKey="id" :pagination="false" :loading="tableLoading"
      bordered>
      <template #bodyCell="{ column, record, text }">
        <template v-if="column.dataIndex === 'name'">
          <a @click="detail(record.id)">{{ text }}</a>
        </template>
        <template v-if="column.dataIndex === 'action'">
          <div class="smart-table-operate">
            <a-button @click="update(record)" v-privilege="'task:edit'" type="link">进入账套</a-button>
          </div>
        </template>
      </template>
    </a-table>

    <div class="smart-query-table-page">
      <a-pagination showSizeChanger showQuickJumper show-less-items :pageSizeOptions="PAGE_SIZE_OPTIONS"
        :defaultPageSize="queryForm.pageSize" v-model:current="queryForm.pageIndex"
        v-model:pageSize="queryForm.pageSize" :total="total" @change="ajaxQuery" @showSizeChange="ajaxQuery"
        :show-total="(total) => `共${total}条`" />
    </div>
    <TaskOperate ref="operateRef" @refresh="ajaxQuery" />
    <UpdateFormModal ref="updateFormModal" @refresh="ajaxQuery" />
  </a-card>
</template>
<script setup lang="ts">
  import { reactive, ref, onMounted,computed } from 'vue';
  import { message, Modal } from 'ant-design-vue';
  import dayjs from 'dayjs';
  import { SmartLoading } from '/@/components/framework/smart-loading';
  import { taskApi } from '/@/api/task/task-api';
  import { PAGE_SIZE, PAGE_SIZE_OPTIONS } from '/@/constants/common-const';
  import { useRouter } from 'vue-router';
  import { smartSentry } from '/@/lib/smart-sentry';
  import TableOperator from '/@/components/support/table-operator/index.vue';
  import { TABLE_ID_CONST } from '/@/constants/support/table-id-const';

  // --------------------------- 企业表格 列 ---------------------------

  const columns = ref([
    {
      title: '客户名称',
      dataIndex: 'name',
      minWidth: 180,
    },
    {
      title: '客户编号',
      dataIndex: 'parentName',
      width: 80,
    },
    {
      title: '客户类型',
      dataIndex: 'implementerName',
      width: 100,
    },
    {
      title: '客户经理',
      dataIndex: 'taskRate',
      width: 100,
    },
    {
      title: '服务顾问',
      width: 100,
      dataIndex: 'planBegin',
    },
    {
      title: '服务状态',
      width: 100,
      dataIndex: 'planEnd',
    },
    {
      title: '客户等级',
      width: 100,
      dataIndex: 'approveName',
    },
    {
      title: '增值税类型',
      width: 120,
      dataIndex: 'stateName',
    },
    {
      title: '操作',
      dataIndex: 'action',
      fixed: 'right',
      width: 100,
    },
  ]);

  // --------------------------- 查询 ---------------------------

  const queryFormState = {
    name: undefined,
    type: undefined,
    parentId:undefined,
    implementer: undefined,
    planBeginStart: undefined,
    planBeginEnd: undefined,
    planEnd: undefined,
    approve: undefined,
    state: undefined,
    pageIndex: 1,
    pageSize: PAGE_SIZE,
  };
  const queryForm = reactive({ ...queryFormState });
  const tableLoading = ref(false);
  const tableData = ref([]);
  const total = ref(0);
  const planBegin=ref([]);

    let selectedRowKeys = ref([]);
    let selectedRows = ref([]);
    // 是否有选中：用于 批量操作按钮的禁用
    const hasSelected = computed(() => selectedRowKeys.value.length > 0);

    function onSelectChange(keyArray, selectRows) {
      selectedRowKeys.value = keyArray;
      selectedRows.value = selectRows;
    }

  function resetQuery() {
    Object.assign(queryForm, queryFormState);
    planBegin.value=[];
    ajaxQuery();
  }

  async function ajaxQuery() {
   const list = [{"name":"佛山友科财税服务有限公司","parentName":"001","implementerName":"非代账客户","taskRate":"阿静","planBegin":"杨生","planEnd":"服务中",
"approveName":"一般客户","stateName":"小规模纳税人"
}];
        total.value = 1;
        tableData.value = list;
  }

  // --------------------------- 删除 ---------------------------

  function confirmDelete(taskId) {

  }

  onMounted(ajaxQuery);
</script>
